//
//  NewMediaPopView.m
//  TryShopping
//
//  Created by LiYinDi on 16/6/14.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "NewMediaPopView.h"
@interface NewMediaPopView()
{
    UIImageView *bgImageView;
    
//    UIButton *couponBtn;
//    UILabel *couponLineLabel;
    
    UIButton *marketingActivityBtn;
    UILabel *marketingActivityLineLabel;
    
    UIButton *informationBtn;
    UILabel *informationLineLabel;
    
    UIButton *scenesBtn;
    UILabel *scenesLineLabel;
    
    UIButton *customBtn;

}
@end
@implementation NewMediaPopView
-(instancetype)init
{
    self=[super init];
    if (self) {
        [self createUI];
        [self setAutoLayout];
    }
    return self;
}
-(void)createUI
{
    UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [self addGestureRecognizer:singleTap];
    
    bgImageView =[[UIImageView alloc] init];
    //    [bgImageView setBackgroundColor:[UIColor colorWithRed:25.0/255.0 green:39.0/255.0 blue:5.0/255.0 alpha:0.88]];
    [bgImageView setImage:[UIImage imageNamed:@"tanchubeijing"]];
    
    [self addSubview:bgImageView];
    
    
//    couponBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//    [couponBtn setTitle:@"优惠券" forState:UIControlStateNormal];
//    [couponBtn addTarget:self action:@selector(couponBtnClick) forControlEvents:UIControlEventTouchUpInside];
//     couponBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
//    [couponBtn setImage:[UIImage imageNamed:@"youhuijuan"] forState:UIControlStateNormal];
//    couponBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置button的内容横向居中
//    couponBtn.contentEdgeInsets=UIEdgeInsetsMake(0,15,0,0);
//    
//    [self addSubview:couponBtn];
    
//    couponLineLabel=[[UILabel alloc] init];
//    [couponLineLabel setBackgroundColor:[UIColor colorWithRed:48.0f/255.0f green:83.0f/255.0f blue:7.0f/255.0f alpha:1.0]];
//    [self addSubview:couponLineLabel];
    
    
    marketingActivityBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [marketingActivityBtn setTitle:@"营销活动" forState:UIControlStateNormal];
     marketingActivityBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [marketingActivityBtn addTarget:self action:@selector(marketingActivityBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [marketingActivityBtn setImage:[UIImage imageNamed:@"yingxiaohuodong"] forState:UIControlStateNormal];
    marketingActivityBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置button的内容横向居中
    marketingActivityBtn.contentEdgeInsets=UIEdgeInsetsMake(0,15,0,0);
    [self addSubview:marketingActivityBtn];
    
    marketingActivityLineLabel=[[UILabel alloc] init];
    [marketingActivityLineLabel setBackgroundColor:[UIColor colorWithRed:48.0f/255.0f green:83.0f/255.0f blue:7.0f/255.0f alpha:1.0]];
    [self addSubview:marketingActivityLineLabel];
    
    informationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [informationBtn setTitle:@"资讯" forState:UIControlStateNormal];
    informationBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];

    [informationBtn addTarget:self action:@selector(informationBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [informationBtn setImage:[UIImage imageNamed:@"zixun"] forState:UIControlStateNormal];
    informationBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置button的内容横向居中
    informationBtn.contentEdgeInsets=UIEdgeInsetsMake(0,15,0,0);
    [self addSubview:informationBtn];
    
    
    informationLineLabel=[[UILabel alloc] init];
    [informationLineLabel setBackgroundColor:[UIColor colorWithRed:48.0f/255.0f green:83.0f/255.0f blue:7.0f/255.0f alpha:1.0]];
    [self addSubview:informationLineLabel];
    
    
    scenesBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [scenesBtn setTitle:@"场景" forState:UIControlStateNormal];
     scenesBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [scenesBtn addTarget:self action:@selector(scenesBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [scenesBtn setImage:[UIImage imageNamed:@"changjing"] forState:UIControlStateNormal];
    scenesBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置button的内容横向居中
    scenesBtn.contentEdgeInsets=UIEdgeInsetsMake(0,15,0,0);
    [self addSubview:scenesBtn];
    
    scenesLineLabel=[[UILabel alloc] init];
    [scenesLineLabel setBackgroundColor:[UIColor colorWithRed:48.0f/255.0f green:83.0f/255.0f blue:7.0f/255.0f alpha:1.0]];
    [self addSubview:scenesLineLabel];

    
    customBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [customBtn setTitle:@"自定义" forState:UIControlStateNormal];
     customBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [customBtn addTarget:self action:@selector(customBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [customBtn setImage:[UIImage imageNamed:@"zidingyi"] forState:UIControlStateNormal];
    customBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置button的内容横向居中
    customBtn.contentEdgeInsets=UIEdgeInsetsMake(0,15,0,0);
    [self addSubview:customBtn];
    
    
}
-(void)couponBtnClick
{
    
    if ([self.delegate respondsToSelector:@selector(couponButtonClick)]) {
        [self.delegate couponButtonClick];
    }
    
    [self removeFromSuperview];
}
-(void)marketingActivityBtnClick
{
    
    if ([self.delegate respondsToSelector:@selector(marketingActivityButtonClick)]) {
        [self.delegate marketingActivityButtonClick];
    }
    [self removeFromSuperview];
}
-(void)informationBtnClick
{
    
    if ([self.delegate respondsToSelector:@selector(informationButtonClick)]) {
        [self.delegate informationButtonClick];
    }
    [self removeFromSuperview];
}
-(void)scenesBtnClick
{
    if ([self.delegate respondsToSelector:@selector(scenesButtonClick)]) {
        [self.delegate scenesButtonClick];
    }
    [self removeFromSuperview];
}
-(void)customBtnClick
{
    if ([self.delegate respondsToSelector:@selector(customButtonClick)]) {
        [self.delegate customButtonClick];
    }
    [self removeFromSuperview];
}
-(void)handleSingleTap:(UITapGestureRecognizer *)sender
{
    [self removeFromSuperview];
}
- (void)show
{
    // 获得主窗口
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.frame= CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [window addSubview:self];
    
    
}
-(void)setAutoLayout
{
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@170);
        make.height.equalTo(@224);
        make.top.equalTo(self.mas_top).with.offset(60);
        make.right.equalTo(self.mas_right).with.offset(-8);
    }];
//    [couponBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.equalTo(bgImageView.mas_width);
//        //        make.right.equalTo(bgImageView.mas_right);
//        make.centerX.equalTo(bgImageView.mas_centerX);
//        make.top.equalTo(bgImageView.mas_top).with.offset(5);
//        make.height.equalTo(bgImageView.mas_height).dividedBy(5);
//    }];
//    [couponLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(bgImageView.mas_left).with.offset(7);
//        make.right.equalTo(bgImageView.mas_right).with.offset(-7);
//        make.bottom.equalTo(couponBtn.mas_bottom);
//        make.height.equalTo(@1);
//    }];
    
    [marketingActivityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(bgImageView.mas_width);
        //        make.right.equalTo(bgImageView.mas_right);
        make.centerX.equalTo(bgImageView.mas_centerX);
        make.top.equalTo(bgImageView.mas_top).with.offset(5);
        make.height.equalTo(bgImageView.mas_height).dividedBy(4);
    }];
    [marketingActivityLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgImageView.mas_left).with.offset(7);
        make.right.equalTo(bgImageView.mas_right).with.offset(-7);
        make.bottom.equalTo(marketingActivityBtn.mas_bottom);
        make.height.equalTo(@1);
    }];
    
    [informationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(bgImageView.mas_width);
        //        make.right.equalTo(bgImageView.mas_right);
        make.centerX.equalTo(bgImageView.mas_centerX);
        make.top.equalTo(marketingActivityBtn.mas_bottom);
        make.height.equalTo(bgImageView.mas_height).dividedBy(4);
    }];
    [informationLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgImageView.mas_left).with.offset(7);
        make.right.equalTo(bgImageView.mas_right).with.offset(-7);
        make.bottom.equalTo(informationBtn.mas_bottom);
        make.height.equalTo(@1);
    }];
    
    [scenesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(bgImageView.mas_width);
        //        make.right.equalTo(bgImageView.mas_right);
        make.centerX.equalTo(bgImageView.mas_centerX);
        make.top.equalTo(informationBtn.mas_bottom);
        make.height.equalTo(bgImageView.mas_height).dividedBy(4);
    }];
    [scenesLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgImageView.mas_left).with.offset(7);
        make.right.equalTo(bgImageView.mas_right).with.offset(-7);
        make.bottom.equalTo(scenesBtn.mas_bottom);
        make.height.equalTo(@1);
    }];

    [customBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(bgImageView.mas_width);
        //        make.right.equalTo(bgImageView.mas_right);
        make.centerX.equalTo(bgImageView.mas_centerX);
        make.top.equalTo(scenesBtn.mas_bottom);
        make.height.equalTo(bgImageView.mas_height).dividedBy(4);
    }];

    
}


@end
